package com.yifi.common.base;

import org.apache.log4j.Logger;

import com.jfinal.aop.Before;
import com.yifi.common.model.Syslog;
import com.yifi.common.utils.ToolSession;
import com.yifi.interceptor.LoginInterceptor;
import com.yifi.system.domain.MisUser;


@Before(LoginInterceptor.class)
public class BaseController extends InitController {
	private static Logger log = Logger.getLogger(BaseController.class);
	
	protected Syslog reqSysLog;			// 当前访问日志
	/**
	 * 设置日志描述
	 * @param description
	 */
	//设置描述
	protected void setLogKindDesc(String status,String description){
		reqSysLog.setStatus(status);
		reqSysLog.setDescription(description);
	}
	//登录
	protected void loginDesc(String description){
		setLogKindDesc("登录",description);
	}
	//新增
	protected void addDesc(String description){
		setLogKindDesc("新增",description);
	}
	//编辑
	protected void editDesc(String description){
		setLogKindDesc("修改",description);
	}
	//删除
	protected void delDesc(String description){
		setLogKindDesc("删除",description);
	}
	//导入
	protected void impDesc(String description){
		setLogKindDesc("导入",description);
	}
	//导出
	protected void expDesc(String description){
		setLogKindDesc("导出",description);
	}
	protected void saveDesc(String description){
		setLogKindDesc("保存",description);
	}
	//查询
	protected void queryDesc(String description){
		setLogKindDesc("查询",description);
	}
	
	/************************************		get 	set 	方法		************************************************/
	public Syslog getReqSysLog() {
		return reqSysLog;
	}

	public void setReqSysLog(Syslog reqSysLog) {
		MisUser misUser=ToolSession.getUser(this);
		if(misUser!=null)
		{
			reqSysLog.setUserids(misUser.getCname());
		}
		else
		{
			reqSysLog.setUserids("bug");
		}
		this.reqSysLog = reqSysLog;
	}
	
	public void setReqSysLogJwt(Syslog reqSysLog,String uid) {
		reqSysLog.setDevicetype("app");
		reqSysLog.setUserids(uid);
		this.reqSysLog = reqSysLog;
	}
}
